package com.company;

import com.sun.xml.internal.ws.org.objectweb.asm.ClassAdapter;

import java.util.ArrayList;

// 泛型
// 泛型就是定义一种模板
public class GenericParadigm{
    public GenericParadigm(){

//        ArrayList<String> str = new ArrayList<String>();
//        str.add("ldq");
//        str.add("link");
//        String f = str.get(0);
//        System.out.println(f);

//        Pair<String> p = new Pair<>("Xiao","Ming");
//        Pair<Integer,Integer> p = new Pair<>(18,20);
//        Pair<Integer,Integer> p2 = Pair.create(1,2);
//        Integer first = p.getFirst();
//        Integer last = p.getLast();
//        System.out.println(first);
//        System.out.println(last);
//        System.out.println(p.getClass() == Pair.class);


        Class<String> clazz = String.class;
//        String str = clazz.newInstance();
        Class<? super String> sup = clazz.getSuperclass();

    }
}
class Pair<T,K> {

    private T first;
    private T last;

    public Pair(T first,T last){
        this.first = first;
        this.last = last;
    }

    public String toString(){
        return "Pair(" + first + "," + last + ")";
    }

    static <K>Pair create(K first, K last){
        return new Pair(first,last);
    }

    public T getFirst() {
        return first;
    }


    public void setFirst(T first) {
        this.first = first;
    }

    public T getLast() {
        return last;
    }

    public void setLast(T last) {
        this.last = last;
    }

}

